#include "da.h"

struct dstr dstr_from_cstr(char const *text)
{
	struct dstr d = DA_INIT;

	for (usize i = 0; text[i] != 0; ++i) {
		DA_APPEND(d, text[i]);
	}
	return d;
}

bool dstr_eq(struct dstr *lhs, struct dstr *rhs)
{
	if (lhs->len != rhs->len)
		return false;

	for (usize i = 0; i < lhs->len; ++i) {
		if (lhs->data[i] != rhs->data[i])
			return false;
	}
	return true;
}

bool dstr_eq_cstr(struct dstr *lhs, char const *rhs)
{
	for (usize i = 0; i < lhs->len; ++i) {
		if (rhs[i] == 0 || lhs->data[i] != rhs[i])
			return false;
	}
	return rhs[lhs->len] == 0;
}
